'use strict';

const puppeteer = require('puppeteer');

(async () => {
	const browser = await puppeteer.launch({headless:false,});
	const page =  await browser.newPage();
	await page.goto('http://ab.58.com/ershoufang/');
	 // let scrollEnable = true;
	 // let scrollStep = 500; //每次滚动的步长
	 // while (scrollEnable) {
	 // scrollEnable = await page.evaluate((scrollStep) => {
	 // 	let scrollTop = document.scrollingElement.scrollTop;
	 // 	document.scrollingElement.scrollTop = scrollTop + scrollStep;
	 // 	return document.body.clientHeight > scrollTop + 1080 ? true : false
	 // }, scrollStep);
	 // await page.waitFor(500);
	 // }
	const a = ".next"
	while(true) {
		const next = await page.$(a);
		if (next) {
			await next.click();
			await page.waitFor(2000)
		}else{
			break
		}
	}
  	await page.screenshot({path: 'taobao.png'});
  	await browser.close();
})();